package com.org.cardplayer.game;

/**
 * @author Thai Son @ This class implement card , include suite and its value
 * @see {@link #Card(CardSuite, int)}
 */
public class Card {
	/**
	 * card suite
	 */
	private CardSuite suite;
	/**
	 * card value
	 */
	private int value;

	/**
	 * Constructor method for Card
	 * 
	 * @param Cardsuite
	 * @param int
	 * @return Card
	 */
	public Card(CardSuite suite, int value) {
		super();
		this.suite = suite;
		this.value = value;
	}

	public CardSuite getSuite() {
		return suite;
	}

	public void setSuite(CardSuite suite) {
		this.suite = suite;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((suite == null) ? 0 : suite.hashCode());
		result = prime * result + value;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Card other = (Card) obj;
		if (suite != other.suite)
			return false;
		if (value != other.value)
			return false;
		return true;
	}

	/**
	 * convert card to String for display
	 */
	@Override
	public String toString() {
		String v;
		String s;
		switch (this.suite) {
		case CLUB:
			s = "c";
			break;
		case SPADE:
			s = "s";
			break;
		case HEART:
			s = "h";
			break;
		case DIAMOND:
			s = "d";
			break;
		default:
			s = "";
			break;
		}
		switch (this.value) {
		case 13:
			v = "K";
			break;
		case 12:
			v = "Q";
			break;
		case 11:
			v = "J";
			break;
		case 10:
			v = "T";
			break;
		default:
			v = "" + this.value;
			break;
		}

		return v + s;
	}

}
